package com.kfm.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

@WebListener("/seesioinattr")
public class SessionAttributeListener implements HttpSessionAttributeListener {

    @Override
    public void attributeAdded(HttpSessionBindingEvent se) {
        String key = se.getName();
        Object value = se.getValue();
        System.out.println("session中添加了 key = " + key + ", value = " + value);
    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent se) {
        String key = se.getName();
        Object value = se.getValue();
        System.out.println("session中删除了 key = " + key + ", value = " + value);
    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent se) {
        String key = se.getName();
        Object value = se.getValue();
        Object newValue = se.getSession().getAttribute(key);
        System.out.println("session中将 key = " + key + "的 value " + value + " 替换为了 " + newValue);
    }
}
